import { createWebHistory, createRouter } from 'vue-router'
import Layout from '@/layout'
import { TrendCharts } from '@element-plus/icons-vue'

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/sociallogin',
    component: () => import('@/views/socialLogin'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '/error',
    component: () => import('@/views/error/Error'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/workbench',
    children: [
      {
        path: 'workbench',
        component: () => import('@/views/dashboard/index.vue'),
        name: 'workbench',
        meta: {
          title: "工作台",
          icon: "dashboard"
        }
      }
      
    ]
  },
  {
    path: '/inspection',
    component: Layout,
    redirect: '/inspection/method',
    meta: {
      title: '检验管理',
      icon: 'inspection'
    },
    children: [
      {
        path: 'method',
        component: () => import('@/views/inspection/MethodManage.vue'),
        name: 'InspectionMethod',
        meta: {
          title: '检验方式设定'
        }
      },
      {
        path: 'instrument',
        component: () => import('@/views/inspection/InstrumentManage.vue'),
        name: 'InspectionInstrument',
        meta: {
          title: '检验器具管理'
        }
      },
      {
        path: 'category',
        component: () => import('@/views/inspection/ItemCategoryManage.vue'),
        name: 'InspectionCategory',
        meta: {
          title: '检测项目分类与设置'
        }
      }
    ]
  },
  {
    path: '/qualityStandard',
    component: Layout,
    redirect: '/qualityStandard/manage',
    meta: {
      title: '质检标准管理',
      icon: 'qualityStandard'
    },
    children: [
      {
        path: 'manage',
        name: 'QualityStandardManage',
        component: () => import('@/views/qualityStandard/StandardManage.vue'),
        meta: { title: '质检标准' }
      },
      {
        path: 'item',
        name: 'QualityItemManage',
        component: () => import('@/views/qualityStandard/ItemManage.vue'),
        meta: { title: '质检项' }
      }
    ]
  },
  {
    path: '/sampling',
    component: Layout,
    redirect: '/sampling/range',
    meta: {
      title: '抽样策略',
      icon: 'sampling'
    },
    children: [
      {
        path: 'range',
        name: 'SamplingRange',
        component: () => import('@/views/sampling/SamplingRange.vue'),
        meta: { title: '抽样范围设置' }
      },
      {
        path: 'level',
        name: 'InspectionLevel',
        component: () => import('@/views/sampling/InspectionLevel.vue'),
        meta: { title: '检验水平设置' }
      }
    ]
  },
  {
    path: '/task',
    component: Layout,
    redirect: '/task/plan',
    meta: {
      title: '任务管理',
      icon: 'task'
    },
    children: [
      {
        path: 'plan',
        name: 'PlanManage',
        component: () => import('@/views/task/PlanManage.vue'),
        meta: { title: '检验计划制定' }
      },
      {
        path: 'task',
        name: 'TaskManage',
        component: () => import('@/views/task/TaskManage.vue'),
        meta: { title: '工序质检任务管理' }
      }
    ]
  },
  {
    path: '/record',
    component: Layout,
    redirect: '/record/inspection',
    meta: {
      title: '数据记录',
      icon: 'document'
    },
    children: [
      {
        path: 'inspection',
        name: 'InspectionRecord',
        component: () => import('@/views/record/InspectionRecord.vue'),
        meta: { title: '巡检记录' }
      },
      {
        path: 'check',
        name: 'CheckRecord',
        component: () => import('@/views/record/CheckRecord.vue'),
        meta: { title: '点检记录' }
      },
      {
        path: 'quality',
        name: 'QualityRecord',
        component: () => import('@/views/record/QualityRecord.vue'),
        meta: { title: '检验记录' }
      },
      {
        path: 'exception',
        name: 'ExceptionRecord',
        component: () => import('@/views/record/ExceptionRecord.vue'),
        meta: { title: '异常记录' }
      }
    ]
  },
  {
    path: '/standard',
    component: Layout,
    redirect: '/standard/inspection',
    meta: {
      title: '标准管理',
      icon: 'standard'
    },
    children: [
      {
        path: 'inspection',
        name: 'InspectionStandard',
        component: () => import('@/views/standard/InspectionStandard.vue'),
        meta: { title: '点巡检标准' }
      },
      {
        path: 'process',
        name: 'ProcessStandard',
        component: () => import('@/views/standard/ProcessStandard.vue'),
        meta: { title: '工序检验标准' }
      }
    ]
  },
  {
    path: '/suspect',
    component: Layout,
    redirect: '/suspect/index',
    meta: {
      title: '可疑品管理',
      icon: 'warning'
    },
    children: [
      {
        path: 'index',
        name: 'SuspectItem',
        component: () => import('@/views/suspect/SuspectItem.vue'),
        meta: { title: '可疑品管理' }
      }
    ]
  },
  {
    path: '/special',
    component: Layout,
    redirect: '/special/issue',
    meta: {
      title: '专项问题管理',
      icon: 'flag'
    },
    children: [
      {
        path: 'issue',
        name: 'SpecialIssue',
        component: () => import('@/views/special/SpecialIssue.vue'),
        meta: { title: '专项问题管理' }
      }
    ]
  },
  {
    path: '/spare',
    component: Layout,
    redirect: '/spare/part',
    meta: {
      title: '备件信息管理',
      icon: 'tools'
    },
    children: [
      {
        path: 'part',
        name: 'SparePartManage',
        component: () => import('@/views/spare/SparePartManage.vue'),
        meta: { title: '备件信息管理' }
      }
    ]
  },
  {
    path: '/work',
    component: Layout,
    redirect: '/work/hour',
    meta: {
      title: '工时管理',
      icon: 'clock'
    },
    children: [
      {
        path: 'hour',
        name: 'WorkHourManage',
        component: () => import('@/views/work/WorkHourManage.vue'),
        meta: { title: '工时管理' }
      }
    ]
  }
  
]

const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_APP_ROUTER_PREFIX),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router
